package zdsoft.nbfsc.task;

import sense.vitality.ioc.SenseInjection;
import sense.vitality.protocol.ObjectResult;
import sense.vitality.protocol.Stuff;
import sense.vitality.security.Authentication;
import sense.vitality.security.Passport;
import sense.vitality.security.entity.Privilege;
import sense.vitality.task.IntellTask;
import sense.vitality.verify.Parameter;


/**
 *
 * @author elegance
 */
public class QueryPrivilegesTask extends IntellTask {

    @SenseInjection
    private Authentication authentication;

    @Override
    protected Stuff execute(Stuff request) {
        Param param = request.getParameter();
        ObjectResult<Privilege> orp = authentication.queryPrivileges(param.getPassport());
        Stuff resp = request.instanceResponse(orp.getResult());
        if (resp.getResult().isSuccess()) {
            resp.setTargetObjects(orp.getTargetObjects());
        }
        return resp;
    }

    public static class Param extends Parameter {

        private Passport passport;

        public Passport getPassport() {
            return passport;
        }

        public void setPassport(Passport passport) {
            this.passport = passport;
        }
    }
}
